typescript-ts-mode: align ternary-chain branches (bug#78187)
authorKonstantin Kharlamov <Hi-Angel@yandex.ru>
Thu, 1 May 2025 13:28:29 +0000 (20:28 +0700)
committerYuan Fu <casouri@gmail.com>
Fri, 16 May 2025 03:09:26 +0000 (20:09 -0700)
* lisp/progmodes/typescript-ts-mode.el:
(typescript-ts-mode--indent-rules): Make sure each new ternary
branch is aligned with the previous one.
* test/lisp/progmodes/typescript-ts-mode-resources/indent.erts:
(Chained ternary expressions): New test.

lisp/progmodes/typescript-ts-mode.el
test/lisp/progmodes/typescript-ts-mode-resources/indent.erts

index f1410df642131e65d6f85428d6defd03f4857512..6cc1eb0bea975846c911f3460b35a4a54d667559 100644 (file)
@@ -118,7 +118,7 @@ Argument LANGUAGE is either `typescript' or `tsx'."
      ((and (parent-is "comment") c-ts-common-looking-at-star)
       c-ts-common-comment-start-after-first-star -1)
      ((parent-is "comment") prev-adaptive-prefix 0)
-     ((parent-is "ternary_expression") parent-bol typescript-ts-mode-indent-offset)
+     ((parent-is "ternary_expression") standalone-parent typescript-ts-mode-indent-offset)
      ((parent-is "member_expression") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "named_imports") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "statement_block") parent-bol typescript-ts-mode-indent-offset)
index ef7368602d6b96111e78b4b9f2e8f9019222e9ad..8abaa81c6275765e2d35e006da2796535f3ca7d5 100644 (file)
@@ -93,6 +93,15 @@ const foo = () => {
 };
 =-=-=
 
+Name: Chained ternary expressions
+
+=-=
+const a = cond1 ? 1
+  : cond2 ? 2
+  : cond3 ? 3
+  : 4;
+=-=-=
+
 Code:
   (lambda ()
     (setq indent-tabs-mode nil)